# ##########################################
# Setup the cmake Qt path.  Assumes the Qt installer has set QTDIR to the
# root of the Qt SDK or the user has added the environment variable.
SET( HAS_QT FALSE )
IF( WIN32 )
	IF( SIZEOF_VOID_P EQUAL "4" )
		SET( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "$ENV{QTDIR}\\Qt5.1.0\\5.1.0\\msvc2012\\lib\\cmake" )
		IF( EXISTS $ENV{QTDIR}\\Qt5.1.0\\5.1.0\\msvc2012\\lib\\cmake )
			SET( HAS_QT TRUE )
		ENDIF()
	ELSE()
		SET( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "$ENV{QTDIR}\\Qt5.1.0\\5.1.0\\msvc2012_64\\lib\\cmake" )
		IF( EXISTS $ENV{QTDIR}\\Qt5.1.0\\5.1.0\\msvc2012_64\\lib\\cmake )
			SET( HAS_QT TRUE )
		ENDIF()
	ENDIF()
ELSE()
	# On OsX, assume default installation in the user home directory.
	GET_FILENAME_COMPONENT( HOME_DIR "~" ABSOLUTE )
	SET( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${HOME_DIR}/Qt/5.1.0/clang_64/lib/cmake/" )
	IF( EXISTS "${HOME_DIR}/Qt/5.1.0/clang_64/lib/cmake/" )
		SET( HAS_QT TRUE )
	ENDIF()
ENDIF()


# ##########################################
IF( HAS_QT )

# ##########################################
SET( CMAKE_INCLUDE_CURRENT_DIR ON )


# ##########################################
# Find the Qt packages.
FIND_PACKAGE( Qt5Widgets REQUIRED )


# ##########################################
# Include files.
SET( INCLUDE_FILES
	Include/Gfed/Gfed.hpp
	Include/Gfed/GameDescription.hpp
)


# ##########################################
# Source files.
SET( SOURCE_FILES
	Source/Gfed.cpp
	Source/GameDescription.cpp
)


# ##########################################
# QT Creator generated file list.  No extentions.
SET( QT_FILES
	UI/mainwindow
	UI/optionsdialog
	UI/createprojectdialog
	UI/assettreeeditor
)


# ##########################################
# Loop through the Qt files and setup moc'ing
# and file lists.
FOREACH( file ${QT_FILES} )
	QT5_WRAP_UI( QT_GEN_UI_FILES ${file}.ui )
	QT5_WRAP_CPP( QT_GEN_HEADER_FILES ${file}.h )
	SET( QT_UI_FILES "${QT_UI_FILES};${file}.ui" )
	SET( QT_SOURCE_FILES "${QT_SOURCE_FILES};${file}.h;${file}.cpp" )
ENDFOREACH()


# ##########################################
# Win32 specifics.
IF( WIN32 )
	SET( EXETYPE WIN32 )
	SET( WINLIBS Qt5::WinMain )
ENDIF()


# ##########################################
# Create the tool.
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_LIST_DIR}/Include ${CMAKE_CURRENT_LIST_DIR}/UI ${CMAKE_CURRENT_LIST_DIR}/JSon )

ADD_EXECUTABLE( Gfed ${EXETYPE}
	${INCLUDE_FILES}
	${SOURCE_FILES}
	${QT_SOURCE_FILES}
	${QT_GEN_UI_FILES}
	${QT_GEN_HEADER_FILES}
)
TARGET_LINK_LIBRARIES( Gfed ${WINLIBS} Core FileSystem )
QT5_USE_MODULES( Gfed Widgets )


# ##########################################
SOURCE_GROUP( "Generated Files" FILES ${QT_GEN_UI_FILES} ${QT_GEN_HEADER_FILES} )
SOURCE_GROUP( "UI Files" FILES ${QT_UI_FILES} )


# ##########################################
# Group the tools.
SET_PROPERTY( TARGET Gfed PROPERTY FOLDER Applications/Tools )


# ##########################################
ELSE( HAS_QT )
	MESSAGE( "QT Not Found!  Gfed not added to build." )
ENDIF()

